package algorithm.tree.binarySortTree_BST;

public class Node {
    int val;
    Node left;
    Node right;

    public Node(int val) {
        this.val = val;
    }

    @Override
    public String toString() {
        return val+"";
    }
    public void add(Node node){
        if(node == null)
            return;
        if (node.val<this.val){
            if (this.left == null){
                this.left = node;
            }else{
                //向左递归添加
                this.left.add(node);
            }
        }else{
            if (this.right == null){
                this.right = node;
            }else{
                //右节点不为空就递归添加
                this.right.add(node);
            }
        }
    }
}
